package com.ruoyi.comprehensive.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.comprehensive.domain.SoldierRightsDeclare;
import com.ruoyi.comprehensive.service.ISoldierRightsDeclareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 退役军人权益维护信息Controller
 *
 * @author jeffery
 * @date 2021-09-01
 */
@RestController
@RequestMapping("/comprehensive/declare")
public class SoldierRightsDeclareController extends BaseController {
    @Autowired
    private ISoldierRightsDeclareService soldierRightsDeclareService;

    /**
     * 查询退役军人权益维护信息列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:declare:list')")
    @GetMapping("/list")
    public TableDataInfo list(SoldierRightsDeclare soldierRightsDeclare) {
        startPage();
        List<SoldierRightsDeclare> list = soldierRightsDeclareService.selectSoldierRightsDeclareList(soldierRightsDeclare);
        return getDataTable(list);
    }

    /**
     * 导出退役军人权益维护信息列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:declare:export')")
    @Log(title = "退役军人权益维护信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SoldierRightsDeclare soldierRightsDeclare) {
        List<SoldierRightsDeclare> list = soldierRightsDeclareService.selectSoldierRightsDeclareList(soldierRightsDeclare);
        ExcelUtil<SoldierRightsDeclare> util = new ExcelUtil<SoldierRightsDeclare>(SoldierRightsDeclare.class);
        return util.exportExcel(list, "退役军人权益维护信息数据");
    }

    /**
     * 获取退役军人权益维护信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:declare:query')")
    @GetMapping(value = "/{declareId}")
    public AjaxResult getInfo(@PathVariable("declareId") Long declareId) {
        return AjaxResult.success(soldierRightsDeclareService.selectSoldierRightsDeclareByDeclareId(declareId));
    }

    /**
     * 新增退役军人权益维护信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:declare:add')")
    @Log(title = "退役军人权益维护信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SoldierRightsDeclare soldierRightsDeclare) {
        return toAjax(soldierRightsDeclareService.insertSoldierRightsDeclare(soldierRightsDeclare));
    }

    /**
     * 修改退役军人权益维护信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:declare:edit')")
    @Log(title = "退役军人权益维护信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SoldierRightsDeclare soldierRightsDeclare) {
        return toAjax(soldierRightsDeclareService.updateSoldierRightsDeclare(soldierRightsDeclare));
    }

    /**
     * 提交申报
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:declare:commit')")
    @Log(title = "提交申报", businessType = BusinessType.UPDATE)
    @PostMapping("commit")
    public AjaxResult commit(@RequestParam("id") Long id) {
        SoldierRightsDeclare soldierRightsDeclare = new SoldierRightsDeclare();
        soldierRightsDeclare.setDeclareId(id);
        soldierRightsDeclare.setFlowStatus(1);
        Long userId = SecurityUtils.getUserId();
        soldierRightsDeclare.setUpdateBy(userId.toString());
        soldierRightsDeclare.setUpdateTime(new Date());
        return toAjax(soldierRightsDeclareService.updateSoldierRightsDeclare(soldierRightsDeclare));
    }

    /**
     * 完结
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:declare:end')")
    @Log(title = "完结", businessType = BusinessType.UPDATE)
    @PostMapping("end")
    public AjaxResult end(@RequestParam("id") Long id) {
        SoldierRightsDeclare soldierRightsDeclare = new SoldierRightsDeclare();
        soldierRightsDeclare.setDeclareId(id);
        soldierRightsDeclare.setFlowStatus(3);
        return toAjax(soldierRightsDeclareService.updateSoldierRightsDeclare(soldierRightsDeclare));
    }

    /**
     * 删除退役军人权益维护信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:declare:remove')")
    @Log(title = "退役军人权益维护信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{declareIds}")
    public AjaxResult remove(@PathVariable Long[] declareIds) {
        return toAjax(soldierRightsDeclareService.deleteSoldierRightsDeclareByDeclareIds(declareIds));
    }

}
